<!-- 人员维护 -->
<template>
  <div>
    <ChooseShow :menus="menus" @GetTableId="GetTableId" title="全部分类">
      <div slot="operation" class="Head_Top">
        <div class="Top_one">
          <el-button @click="addgroup" size="small" type="primary"
            >新增</el-button
          >
        </div>
        <div class="Top_two">
           <div class="Top_two_radio">
            <el-checkbox v-model="checked">已离职</el-checkbox>
          </div>
          <div class="Top_two_one">
            <el-input placeholder="请输入内容" v-model="listfrom.KeyWord">
              <i
                slot="suffix"
                @click="search"
                class="el-input__icon el-icon-search"
              ></i>
            </el-input>
          </div>
          <div class="Top_two_two1">
            <el-button
              icon="el-icon-refresh"
              size="small"
              class="refresh"
              @click="Toreload"
            ></el-button>
            <!-- <i class="iconfont icon-shuaxin" @click="Toreload"></i> -->
          </div>
        </div>
        <!-- <el-button @click="modal12 = true" type="primary">点击编辑</el-button> -->
      </div>
      <div slot="table">
        <table-cmp
          style="width:100%"
          class="table_cmp"
          :loading="loading"
          :table-data="tableData"
          :table-label="tableLabel"
          @handleButton="handleButton"
          @rowClick="rowClick"
          @cellClick="cellClick"
          @handleSortChange="handleSortChange"
          @handleSelectionChange="handleSelectionChange"
        ></table-cmp>
        <div style="text-align: right;">
          <el-pagination
            v-if="tatolpage > 10"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="listfrom.PageIndex"
            layout=" prev, pager, next"
            :total="tatolpage"
          >
          </el-pagination>
        </div>
      </div>
    </ChooseShow>
    <employpop ref="employpop"></employpop>
  </div>
</template>

<script>
var occupancyDisplay = {
  template: `<div>
           
            <el-button type="text" size="small" v-if='row.Status==3' @click='remove(row)'>删除</el-button>
            <el-button type="text" size="small" v-if='row.Status==2' @click='stop(row)'>停用</el-button>
            <el-button type="text" size="small" v-if='row.Status==3' @click='start(row)'>启用</el-button>
            <el-button type="text" size="small" v-if='row.Status==2' @click='shenhDetail(row)'>编辑</el-button>
  
  </div>`,
  props: ['row'],
  created() {
  },
  methods: {
    shenhDetail(row) {
      this.$emit('shenh-detail', row);
      // console.log(this.row,'1111111');

    },
    remove(row) {
      this.$confirm('此操作将删除该条信息, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let obj = {
            "MN": "RemoveStaff",
            "RequestId": 1,
            "UserId": 1,
            "DataContent": {
              'Ids':this.row.Id
            }
          }
          this.MIX_send(obj);
        }).catch(() => {        
        });

    },
    start(row) {
      this.$confirm('此操作将启用该条信息, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let obj = {
            "MN": "UnCancelStaff",
            "RequestId": 1,
            "UserId": 1,
            "DataContent": {
              'Ids':this.row.Id
            }
          }
          this.MIX_send(obj);
        }).catch(() => {        
        });

    },
    stop(row) {
      this.$confirm('此操作将停用该条信息, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let obj = {
            "MN": "CancelStaff",
            "RequestId": 1,
            "UserId": 1,
            "DataContent": {
              'Ids':this.row.Id
            }
          }
          this.MIX_send(obj);
        }).catch(() => {        
        });

    }
  }
};
var that;
import ChooseShow from "@/components/ChooseShow";
import employpop from "./dialog/employpop";
export default {
  name: "",
  data() {
    return {
      modal12: false,
      loading: false,
      checked: true,
      tatolpage: 0,
      tableData: [],
      listfrom: {
        "Status": '',
        "KeyWord": '',
        "IsStop": '',
        "PageSize": 10,
        "PageIndex": 1
      },
      tableLabel: [
        {          label: '状态', param: 'Status', width: '100', align: 'center', sortable: false, render: (row) => {
            if (row.Status == 0) {
              return '草稿'
            } else if (row.Status == 1) {
              return '待审批'
            } else if (row.Status == 2) {
              return '在职'
            } else if (row.Status == 3) {
              return '离职'
            }
          }
        },
        { label: '工号', param: 'No', align: 'center', width: '100', sortable: false },
        { label: '姓名', param: 'Name', align: 'center', width: '100',},
        { label: '性别', param: 'Sex', align: 'center' ,width: '70',},
        { label: '隶属部门', param: 'OrganizationName', align: 'center' },
        { label: '岗位', param: 'JobsName', align: 'center' },
        { label: '入职时间', param: 'EntryTime', align: 'center' },
        { label: '描述', param: 'Desc', align: 'center' },
        { label: '操作', align: 'center', width: '300',
          component: occupancyDisplay, listeners: {
            'shenh-detail'(row) {
              that.dyapiDetail(row);
            },
          }
        }
      ],
      fromData: {},
      columns: [],
      menus: [],
    };
  },
  components: {
    employpop,
    ChooseShow
  },
  watch: {
    "checked":function (params) {
      this.getlistdata();
    },
    "$store.state.Humanmanage.QueryStaff": function (data) {
      this.tatolpage = data.ReturnData.DataCount;
      this.tableData = data.ReturnData.Data;
    },
    "$store.state.Humanmanage.UnCancelStaff": function (data) {
      this.$message({
            type: 'success',
            message: '操作成功!'
          });
      this.getlistdata();
    },
    "$store.state.Humanmanage.CancelStaff": function (data) {
      this.$message({
            type: 'success',
            message: '操作成功!'
          });
      this.getlistdata();
    },
    "$store.state.Humanmanage.RemoveStaff": function (data) {
      this.$message({
            type: 'success',
            message: '操作成功!'
          });
      this.getlistdata();
    },
    "$store.state.Humanmanage.QueryJobs":function (data){
      if (data.RequestId ==1) {
        let DataContent = data.ReturnData.DataCount;
        this.tableData = data.ReturnData.Data;
        this.tatolpage = data.ReturnData.DataCount;
          // this.postmainoption = JSON.parse(JSON.stringify(data.ReturnData.Data));
        }
    },
    "$store.state.Humanmanage.QueryOrganizationTree": function (data) {
      this.menus = data.ReturnData;
    },
  },
  methods: {
    dyapiDetail(row){
      this.$refs.employpop.dialogFormVisible = true;
      this.$refs.employpop.formtype = 2;
      this.$refs.employpop.getstaff(row.Id);
    },
    // 添加组
    addgroup() {
      this.$refs.employpop.dialogFormVisible = true;
      this.$refs.employpop.formtype = 1;
    },
    getlistdata() {
      if (this.checked) {
        delete this.listfrom.IsStop;
      } else {
        this.listfrom.IsStop = '1';
      }
      let obj = {
        "MN": "QueryStaff",
        "RequestId": 1,
        "UserId": 1,
        "DataContent": this.listfrom
      }
      this.MIX_send(obj);
    },
     getOrganizationTree() {
      let objor = {
        "MN": "QueryOrganizationTree",
        "RequestId": 1,
        "UserId": 1,
        "DataContent": {}
      }
      this.MIX_send(objor);

    },
    rowClick(data) { },
    handleCurrentChange(data) {
      this.listfrom.PageIndex = data;
      this.getlistdata();
    },
    handleSizeChange(data) {
      // console.log(data,'handleSizeChange');
      this.listfrom.PageSize = data;
      this.getlistdata();
    },
    handleButton(data) { },
    cellClick(data) { },
    handleSortChange(data) { },
    handleSelectionChange(data) { },
    GetTableId(data) {
      this.listfrom.PageIndex = 1;
       if (data =='All') {
        delete this.listfrom.OrganizationId;
      } else{
        this.listfrom.OrganizationId = data.Id;
      }
        this.getlistdata();
    },
    Toreload() {
      this.listfrom = {
        "Status": '',
        "KeyWord": '',
        "Status": '',
        "PageSize": 10,
        "PageIndex": 1
      }
      this.getlistdata();
    },
    search() {
      this.getlistdata();
    },
    // 表格上方筛选slot的事件回调
    add() {
      console.log("表格上方筛选slot的事件回调");
    },
    // 弹出框表单提交
    Commit() {
      // console.log(this.$refs.PopForm.value);
    },
    // 弹出框底部标签页组件事件的回调
    edit(val) {
      console.log(val);
    }
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    that = this;
    this.getlistdata();
    this.getOrganizationTree();
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() { }
};
</script>

<style lang="less" scoped>
.Head_Top {
  width: 100%;
  height: 51px;
  // overflow: hidden;
  display: flex;
  justify-content: space-between;
  .Top_one {
    width: 100px;
  }
  .Top_two {
    // flex: 1;
    display: flex;
    .Top_two_two {
      padding: 10px;
    }
  }
  .Top_three {
    width: 50px;
  }
}
</style>